package firstDay;

import java.util.ArrayList;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;

/**
 * @author nhp
 * @version 1.0
 * @description TODO
 * @date 2024-05-24 17:35
 */
public class LeetCode349 {
    public static void main(String[] args) {
        HashSet<Integer> set = new HashSet<>();
    }

    public int[] intersection(int[] nums1, int[] nums2) {
        if(nums1.length == 0 || nums2.length == 0){
            return null;
        }
        HashSet<Integer> set1 = new HashSet<>();
        HashSet<Integer> set2 = new HashSet<>();
        for(int i = 0 ;i < nums1.length;i++){
            set1.add(nums1[i]);
        }
        for(int i = 0 ;i < nums2.length;i++){
            set2.add(nums2[i]);
        }

        List<Integer> temp = new ArrayList<>();
        Iterator<Integer> iterator = set1.iterator();
        while (iterator.hasNext()){
            Integer next = iterator.next();
            if (set2.contains(next)) {
                temp.add(next);
            }
        }
        int[] result = new int[temp.size()];
        for(int i = 0; i < temp.size();i++){
            result[i] = temp.get(i);
        }
        return result;
    }
}
